import 'package:flutter/material.dart';

class Animated4Page extends StatefulWidget {
  const Animated4Page({super.key});

  @override
  State<Animated4Page> createState() => _Animated4PagePageState();
}

class _Animated4PagePageState extends State<Animated4Page>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = AnimationController(
      vsync: this,
      duration: Duration(seconds: 2), //持续时间
    )..repeat(reverse: true);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: [
            SizedBox(height: 150),
            // 动画组件
            // SlideTransition() 滑动过渡动画组件
            SlideTransition(
              // position: _controller.drive(
              //   Tween(begin: Offset(0, 0), end: Offset(0.5, 1)), //插值器
              // ),
              position: Tween(begin: Offset(0.0, 0.0), end: Offset(0.0, 2.0))
              .chain(CurveTween(curve: Curves.decelerate))
              .chain(CurveTween(curve: Interval(0.5, 1)))
              .animate(_controller),
              child: FlutterLogo(size: 200),
            ),
            SizedBox(height: 200),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                ElevatedButton(
                  onPressed: () {
                    _controller.reset();
                  },
                  child: Text("reset"),
                ),
                ElevatedButton(
                  onPressed: () {
                    _controller.repeat();
                  },
                  child: Text("repeat"),
                ),
                ElevatedButton(
                  onPressed: () {
                    _controller.stop();
                  },
                  child: Text("stop"),
                ),
                ElevatedButton(
                  onPressed: () {
                    _controller.reverse();
                  },
                  child: Text("reverse"),
                ),
                ElevatedButton(
                  onPressed: () {
                    _controller.forward();
                  },
                  child: Text("forward"),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
